package com.hangxiang.approval.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hangxiang.approval.common.IntegerCommon;
import com.hangxiang.approval.common.ReviewerInsertCommon;
import com.hangxiang.approval.common.ReviewerUpdateCommon;
import com.hangxiang.approval.dao.ReviewerDao;
import com.hangxiang.approval.entity.Reviewer;
import com.hangxiang.approval.service.ReviewerService;
import com.hangxiang.approval.vo.ReviewerVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


/**
 * (Reviewer)表服务实现类
 *
 * @author makejava
 * @since 2020-11-24 15:04:09
 */
@Service("reviewerService")
public class ReviewerServiceImpl extends ServiceImpl<ReviewerDao, Reviewer> implements ReviewerService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private ReviewerDao reviewerDao;

    /**
     * 通过ID查询单条数据
     *
     * @param common 主键
     * @return 实例对象
     */
    @Override
    public ReviewerVo queryById(IntegerCommon common) {
        ReviewerVo vo = new ReviewerVo();
        Reviewer reviewer = reviewerDao.selectById(common.getValue());
        BeanUtils.copyProperties(reviewer, vo);
        return vo;
    }


    /**
     * 新增数据
     *
     * @param reviewerInsertCommon 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public Integer insertReviewer(ReviewerInsertCommon reviewerInsertCommon) {
        Reviewer reviewer = new Reviewer();
        BeanUtils.copyProperties(reviewerInsertCommon, reviewer);
        reviewerDao.insert(reviewer);
        return reviewer.getId();
    }

    /**
     * 修改数据
     *
     * @param reviewerUpdateCommon 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public Integer updateReviewer(ReviewerUpdateCommon reviewerUpdateCommon) {
        Reviewer reviewer = new Reviewer();
        BeanUtils.copyProperties(reviewerUpdateCommon, reviewer);
        reviewerDao.updateById(reviewer);
        return reviewer.getId();
    }
}